package com.hypo.controller;

import com.hypo.annotation.LogOperation;
import com.hypo.pojo.PageResult;
import com.hypo.pojo.Result;
import com.hypo.pojo.Student;
import com.hypo.pojo.StudentQueryParam;
import com.hypo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 分页
     */
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam) {
        PageResult pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }

    /**
     * 新增
     */
    @PostMapping
    public Result add(@RequestBody Student student) {
        studentService.add(student);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public Result del(@PathVariable List<Integer> ids) {
        studentService.del(ids);
        return Result.success();
    }

    /**
     * id回显
     */
    @LogOperation
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Student student = studentService.getById(id);
        return Result.success(student);
    }

    /**
     * 修改
     */
    @PutMapping
    public Result modify(@RequestBody Student student) {
        studentService.modify(student);
        return Result.success();
    }

    /**
     * 违纪处理
     */
    @PutMapping("/violation/{id}/{score}")
    public Result handleScore(@PathVariable Integer id, @PathVariable Integer score) {
        studentService.handleScore(id, score);
        return Result.success();
    }
}
